﻿using System;
using System.Linq;
using System.Reflection;

namespace Codeflows.Extensions.Fx.System.Reflection
{
    public static class FriendlyNameExtensions
    {
        public static string GetFriendlyName(this MemberInfo memberInfo)
        {
            var attributes = memberInfo.GetCustomAttributes(typeof(FriendlyNameAttribute), true).Cast<FriendlyNameAttribute>();
            return attributes.Any() ? attributes.Single().Name : memberInfo.Name;
        }
    }
}